﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.DomainObjects;
using System.Data.SqlClient;
using System.Data;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeGetAllProductDataAction:BestLifeDataAction<List<Product>>
    {
        public BestLifeGetAllProductDataAction()
        {
            
        }
        //piumi
        public override List<Product> Body(SqlConnection PConn)
        {
            try
            {
                List<Product> LvList1 = new List<Product>();


                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetAllProduct";

                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                   
                    Product LvItem = new Product();

                    LvItem.Pro_ID = LvReader.GetValue(0).ToString();
                     LvItem.Cat_ID = LvReader.GetValue(1).ToString();
                     LvItem.Subcat_ID = LvReader.GetValue(2).ToString();
                      LvItem.Brand_Name = LvReader.GetValue(3).ToString();
                    //  LvItem.Unit = LvReader.GetValue(4).ToString();
                    // LvItem.Unit_DescriptionLvReader.GetValue(5).ToString();
                     LvItem.Description = LvReader.GetValue(6).ToString();
                     LvItem.Pro_Name = LvReader.GetValue(7).ToString();
                    LvItem.Status = LvReader.GetValue(8).ToString();
                    LvItem.User_Id = LvReader.GetValue(9).ToString();
                     // LvItem.Date_Create = LvReader.GetValue(10).ToString();
                     LvItem.User_Modify = LvReader.GetValue(11).ToString();
                      //  LvItem.Last_Modify = LvReader.GetValue(12).ToString();
                    LvItem.BarCode = LvReader.GetValue(13).ToString();
                  
                    LvList1.Add(LvItem);

                   

                }
                LvReader.Close();
                return LvList1;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
